<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
	<link rel="stylesheet" type="text/css" href="./css/my.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
</head>

<body>
	<div class="collection">
		<div class="goodslist" id="div_goods_list">

		</div>
	</div>
	<!--加载loading-->
	<div class="index_loading">
		<img src="../../image/index_loading.gif" />
		<span>加载中,请稍后...</span>
	</div>
	<div class="collection_stance"></div>
	<div class="collection_footer">
		<div class="btn_select"><input class="aui-checkbox" type="checkbox" id="select_all">全选(<span id="select_number">0</span>)</div>
		<div class="btn_share">
			<div class="qunshare" onclick="showToast('请到商品页面分享!')">分享给朋友</div>
			<div class="friendshare deleteGoods">批量删除</div>
		</div>
	</div>
	<!--暂无数据-->
	<div class="temporarily_data" style="display:none;">
		<img src="../../image/no_date.png" />
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/zepto.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script id="tmpl_goods_list" type="text/x-dot-template">
	<div>
		{{? it}} {{~it:v:i}}
		<div class="aui-flex-col aui-flex-center  aui-border-t-5px">
			<div class="aui-flex-row aui-flex-item-1  aui-flex-center aui-flex-middle" data-itemid="{{=v.goods_id}}">
				<input class="aui-checkbox aui-checkbox-index" type="checkbox" value="{{=v.goods_id}}" name="box">
			</div>
			<div class="aui-flex-item-4  aui-flex-middle aui-padded-10" tapmode {{? v.source_type=='sn' || v.source_type=='vip' ||v.source_type=='mg' }}onclick="openWinto('detail_win','widget://html/{{=v.source_type}}_good_detail_win',{gooditem:'{{!JSON.stringify(v)}}'})"
							{{??}}onclick="openWinto('detail_win','widget://html/good_pdd_jd_detail_win',{source_type:'{{=v.source_type}}',from:'collection',goods_id:'{{=v.goods_id}}',picurls:'{{=v.goods_pic}}',goods_name:'{{=v.goods_name}}',price:'{{=v.goods_price}}',price_after:'{{=v.goods_endprice}}',sales:'{{=v.goods_sales}}',discount:'{{=v.goods_couponmoney}}'})"
							{{?}}>
				<img src="{{=v.goods_pic}}" onerror="this.src='./image/load-img.png'" style="border-radius:5px" />
			</div>
			<div class="aui-flex-item-7 aui-flex-between aui-padded-10" tapmode {{? v.source_type=='sn' || v.source_type=='vip' ||v.source_type=='mg' }}onclick="openWinto('detail_win','widget://html/{{=v.source_type}}_good_detail_win',{gooditem:'{{!JSON.stringify(v)}}'})"
							{{??}}onclick="openWinto('detail_win','widget://html/good_pdd_jd_detail_win',{source_type:'{{=v.source_type}}',from:'collection',goods_id:'{{=v.goods_id}}',picurls:'{{=v.goods_pic}}',goods_name:'{{=v.goods_name}}',price:'{{=v.goods_price}}',price_after:'{{=v.goods_endprice}}',sales:'{{=v.goods_sales}}',discount:'{{=v.goods_couponmoney}}'})"
							{{?}}>
				<h4 class="aui-ellipsis-1 aui-margin-t-5">{{? v.source_type=='mg'}}<span class="mgj_font_style">蘑菇街</span>{{?}}{{? v.source_type=='vip'}}<span class="vip_font_style">唯品会</span>{{?}}{{? v.source_type=='tb'}}<span class="tb_font_style">淘宝</span>{{?}} {{? v.source_type=='jd'}}<span class="jd_font_style">京东</span>{{?}} {{? v.source_type=='pdd'}}<span class="pdd_font_style">拼多多</span>{{?}} {{? v.source_type=='sn'}}<span class="jd_font_style">苏宁</span>{{?}}{{=v.goods_name}}</h4>
				<div><span class="aui-text-color-CD2626 aui-text-pink"><label class="aui-font-size-14">￥</label>{{=v.goods_endprice}}</span><del class="aui-font-size-12 aui-text-dark">￥{{=v.goods_price}}</del></div>
				<div>
					<span class="aui-pull-left aui-padded-l-5"><label class="aui-label aui-label-danger aui-bg-tag-quan">券{{=parseFloat(v.goods_couponmoney *1)}}元</label></span>
					<span class="aui-pull-right aui-padded-r-5"><label class="aui-label aui-label-success aui-bg-tag-money">￥{{= v.goods_endprice}}元</label></span>
				</div>
				<div class="aui-clearfix"></div>
				<!--<div class="aui-bg-tag-quan-0 aui-margin-t-5 aui-label aui-text-white aui-flex-item-12"><label class="pdd_font_style">已售:{{=v.goods_sales}}</label></div>-->
			</div>
			{{~}} {{?}}
		</div>
</script>
<script type="text/javascript">
	var pageParam = {
		pageindex: 1,
		isloaded: true,
	};
	apiready = function() {
		getMyLove();
		getMoreGoods(function() {
			pageParam.pageindex++;
			getMyLove();
		});
	};

	function getMyLove() {
		if (!pageParam.isloaded) {
			return;
		}
		$(".index_loading").show();
		postDataLogin('getMyLoveGoods', {
			pageindex: pageParam.pageindex
		}, function(res, err) {
			$(".index_loading").hide();
			if (res.code == 1) {
				var list = doT.template(($('#tmpl_goods_list')).text());
				$("#div_goods_list").append(list(res.data));
			} else {
				pageParam.isloaded = false;
				if (pageParam.pageindex == 1) {
					$('.temporarily_data').show();
				} else {

					$(".index_loading img").hide();
					$(".index_loading span").html("<div style='color:#dddddd;padding-left:30px'>—这是我的底线—</div>");
					$(".index_loading").show();
				}
			}
		});
		selectAll();
	}

	function selectAll() {
		$("#select_all").unbind('click').click(function() {
			var userids = this.checked;
			$("input[name=box]").each(function() {
				this.checked = userids;
				var length = $("input[name=box]:checked").length;
				console.log(length);
				$("#select_number").html(length);
			});
		});

		$(document).on('click', "input[name=box]", function() {
			var length = $("input[name=box]:checked").length;
			$("#select_number").html(length);
			var len = $("input[name=box]").length;
			if (length == len) {
				$("#select_all").get(0).checked = true;
			} else {
				$("#select_all").get(0).checked = false;
			}
		});
		// 删除的字符串 含批量
		var loveids = '';
		$('.deleteGoods').unbind('click').click(function() {
			var array = new Array(); //设置接受数组
			//遍历获取勾选checkbox元素
			if ($("input[name=box]:checked").length > 99) {
				showToast('单次最多删除100条!');
				return
			}
			if ($("input[name=box]:checked").length == 0) {
				showToast('您没有选中!');
				return
			}
			$("input[name=box]").each(function(index, item) {
				if ($(this).is(":checked")) {
					loveids = $(this).val() + ',' + loveids;
				}
			});
			delMyLoveGoods(loveids);
		})
	}

	function delMyLoveGoods(loveids) {
		showProgress('删除中~')
		postDataLogin('delMyLoveGoods', {
			loveids: loveids
		}, function(ret, err) {
			if (ret && ret.code == 1) {
				$("#div_goods_list").empty();
				showToast(ret.msg);
				pageParam.isloaded = true;
				pageParam.pageindex = 1;
				getMyLove();
				$("#select_number").html(0);
				$("#select_all").get(0).checked = false;
			} else {
				showToast(ret.msg);
			}
		});
	}
</script>

</html>
